/**
 * @param {string} s
 * @return {number}
 */
 var appealSum = function(s) {
  const n = s.length
  const h = c => c.charCodeAt() - 'a'.charCodeAt()
  let ans = 0
  const a = new Array(26).fill(0)
  for(let i = 0; i<n; i++) {
    const c = h(s[i])
    a[c] = i+1
    for(let j = 0; j<26; j++) {
      ans += a[j]
    }
  }
  return ans
};